import Qt 4.7


Item {
    id: root
    anchors.fill: parent
    state: "hidden"
    property alias text: notificationText.text
    property int timeout: 3

    property color backgroundColor: "#000000"
    property color fontColor: "#FFFFFF"
    property int fontSize: 20

    function show() {
        root.state = "visible"
        // if timeout equals to 0, notifications is visible until user taps on screen
        if(timeout > 0)
            timer.start();
    }

    Timer {
        id: timer
        interval: timeout * 1000 // 3 seconds default
        repeat: false

        onTriggered: {
            root.state = "hidden"
        }
    }


    Rectangle {
        anchors.fill: parent
        color: backgroundColor
        opacity: 0.8
        Text {
            id: notificationText
            anchors.centerIn: parent
            color: fontColor
            font.pixelSize: fontSize
        }
    }

    MouseArea {
        anchors.fill: parent
        onClicked: {
            timer.stop();
            root.state = "hidden"
        }
    }

    states: [
        State {
            name: "visible"
            PropertyChanges {
                target: root
                opacity: 1.0
            }
        },
        State {
            name: "hidden"
            PropertyChanges {
                target: root
                opacity: 0.0
            }
        }
    ]

    Behavior on opacity { NumberAnimation {} }
}
